package model;

import dbtools.DataSimpDto;
import io.netty.channel.Channel;
import server.Service;


public class Client {
	private String taskno;
	private String status;
	private Channel channel;
	
	public String getTaskno() {
		return taskno;
	}//任务
	public void setTaskno(String taskno) {
		this.taskno = taskno;
	}
	
	public String getStatus() {
		return status;
	} //状态
	public void setStatus(String status) {
		this.status = status;
	}
	public Channel getMachineChannel() {
		return channel;
	}
	public void setMachineChannel(Channel channel) {
		this.channel = channel;
	}
	
	public boolean isActive()
	{
		boolean isactive=false;
		if(channel.isActive()
			&&channel.isOpen()
			&&channel.isRegistered()
			&&channel.isWritable())
			isactive=true;
		return isactive;
	}
	public void startClient()
	{
    	model.TkInfo outInfo=new model.TkInfo();
		outInfo.setName("startserver");
		String sql="select " +
				" a.pk_task,a.pk_node,a.fd_taskno,a.fd_pl,a.fd_pastdel,a.fd_autostart, " +
				" a.fd_upml,a.fd_upmlbak,a.fd_ftpaddr,a.fd_ftpusr,a.fd_ftppw,a.fd_ftpmul," +
				" a.fd_stat,b.fd_fwno,b.fd_name,b.fd_addr,b.fd_stat" +
				" from t_fw_task a left join t_fw_node b on a.pk_node=b.pk_node " +
				" where a.fd_taskno='"+taskno+"'";
		DataSimpDto dto=new DataSimpDto(sql);
		if(dto.getTotRecord()>0)
		{
			outInfo=Service.addBaseInfo(outInfo,dto,taskno);
			outInfo=Service.addDataBaseInfo(outInfo);
		}
		channel.writeAndFlush(outInfo);
	}
	public void shutdownClient()
	{
    	model.TkInfo outInfo=new model.TkInfo();
		outInfo.setName("shutdown");
		channel.writeAndFlush(outInfo);
	}
}
